﻿// ==============================================================================
// Copyright (c) 2012 Bndy.Net, All rights reserved.
// Created by Bndy on 4/6/2012 9:43:36 PM
//
//                    * * * * * * * * * * * * * 
//                    * MAIL- bndy5337@163.com *       http://www.bndy.net
//                    * Q Q - 81795705 =========================================>
//                    * MSN - bndy5337@msn.com *
//                    * * * * * * * * * * * * * 
//
// ------------------------------------------------------------------------------
// 
// ==============================================================================

using System;

using Net.Bndy.Data;

namespace Net.Bndy.Framework.SqlBuilders
{
    public abstract class SqlBuilder
    {
        private const string ExMsg_RequiredDbFactory = "An instance typed IDbFactory is required.";
        protected const string ExMsg_RequiredPrimaryKey = "Primary Key is required for an entity.";

        public abstract string Insert(EntityBase entity);
        public abstract string Update(EntityBase entity);
        public abstract string Delete(EntityBase entity);

        public static SqlBuilder CreateBuilder(IDbFactory dbFactory)
        {
            if (dbFactory != null)
            {
                SqlBuilder result = null;

                if (dbFactory.GetType().Equals(typeof(MsSqlFactory)))
                {
                    result = new MsSqlBuilder();
                }

                return result;
            }
            else
            {
                throw new Exception(ExMsg_RequiredDbFactory);
            }
        }
    }
}
